/************************************************************************
                                                                     
   Xceed Ultimate ListBox for Silverlight                                                                                                                                            
   Copyright (C) 2010 Xceed Software Inc.    
                                                                     
   This program is provided to you under the terms of the GNU General Public  
   License version 2 as published by the Free Software Foundation. 
        
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY, without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along 
   with this program, if not, write to the Free Software Foundation, Inc., 
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. Visit Xceed.com to find the commercial edition of 
   Xceed Ultimate ListBox for Silverlight.                                    
                                                                      
 **********************************************************************/

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;

namespace Xceed.Silverlight.Data
{
  internal sealed class DataRangeContext
  {
    internal DataRangeContext(
      Type userObjectType,
      IEnumerable<SortDescription> sortDescriptions,
      Predicate<object> filter,
      FilterExpressionBase filterExpression )
    {
      if( userObjectType == null )
        throw new ArgumentNullException( "userObjectType" );

      m_userObjectType = userObjectType;

      if( sortDescriptions == null )
        throw new ArgumentNullException( "sortDescriptions" );

      m_sortDescriptions = new ReadOnlyCollection<SortDescription>( sortDescriptions.ToList() );

      if( m_sortDescriptions.Count <= 0 )
        throw new ArgumentException( "sortDescriptions must have at least one item.", "sortDescriptions" );

      m_filter = filter;
      m_filterExpression = filterExpression;
    }

    public bool Equals( DataRangeContext obj )
    {
      if( this.Filter != obj.Filter )
        return false;
      if( this.FilterExpression != obj.FilterExpression )
        return false;
      if( !this.SortDescriptions.SequenceEqual( obj.SortDescriptions ) )
        return false;
      if( this.UserObjectType != obj.UserObjectType )
        return false;      

      return true;
    }


    #region UserObjectType Property

    internal Type UserObjectType
    {
      get
      {
        return m_userObjectType;
      }
    }

    private Type m_userObjectType; //null

    #endregion UserObjectType Property

    #region SortDescriptions Property

    internal IList<SortDescription> SortDescriptions
    {
      get
      {
        return m_sortDescriptions;
      }
    }

    private IList<SortDescription> m_sortDescriptions; //null

    #endregion SortDescriptions Property

    #region Filter Property

    internal Predicate<object> Filter
    {
      get
      {
        return m_filter;
      }
    }

    private Predicate<object> m_filter; //null

    #endregion Filter Property

    #region FilterExpression Property

    internal FilterExpressionBase FilterExpression
    {
      get
      {
        return m_filterExpression;
      }
    }

    private FilterExpressionBase m_filterExpression; //null

    #endregion FilterExpression Property
  }
}
